package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.uni.domain.DcGoods;
import com.ruoyi.uni.service.IDcGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐品管理Controller
 * 
 * @author hx
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/system/goods")
public class DcGoodsController extends BaseController
{
    @Autowired
    private IDcGoodsService dcGoodsService;

    @PreAuthorize("@ss.hasPermi('system:types:edit')")
    @PostMapping("/move")
    public String moveUp(@RequestBody JSONObject js){
        return dcGoodsService.move(js.getString("id"),js.getInteger("flag"),js.getLong("type"));
    }

    /**
     * 查询餐品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcGoods dcGoods)
    {
        startPage();
        List<DcGoods> list = dcGoodsService.selectDcGoodsList(dcGoods);
        return getDataTable(list);
    }

    /**
     * 导出餐品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:export')")
    @Log(title = "餐品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcGoods dcGoods)
    {
        List<DcGoods> list = dcGoodsService.selectDcGoodsList(dcGoods);
        ExcelUtil<DcGoods> util = new ExcelUtil<DcGoods>(DcGoods.class);
        util.exportExcel(response, list, "餐品管理数据");
    }

    /**
     * 获取餐品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dcGoodsService.selectDcGoodsById(id));
    }

    /**
     * 新增餐品管理
     */
    @PreAuthorize("@ss.hasPermi('system:goods:add')")
    @Log(title = "餐品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcGoods dcGoods)
    {
        dcGoods.setCount(Long.valueOf(100));
        return toAjax(dcGoodsService.insertDcGoods(dcGoods));
    }

    /**
     * 修改餐品管理
     */
    @PreAuthorize("@ss.hasPermi('system:goods:edit')")
    @Log(title = "餐品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcGoods dcGoods)
    {
        return toAjax(dcGoodsService.updateDcGoods(dcGoods));
    }

    /**
     * 删除餐品管理
     */
    @PreAuthorize("@ss.hasPermi('system:goods:remove')")
    @Log(title = "餐品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dcGoodsService.deleteDcGoodsByIds(ids));
    }
}
